<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript" language="javascript">
<!--
function check_assignrole_info(thisForm)
{
	$("#stat").css({"display":"block"});
	$("#stat").html("正在保存内容......");
	_ajax_submit(thisForm, on_success, on_failure);
	return false;
}

function on_success(response)
{
	response1 = eval("("+response+")");
	var stat = document.getElementById("stat");
	if(response1.result == 'ok')
	{
		alert(response1.sucmsg);
		stat.innerHTML = "OK，正在重定向......";
		reloadPage();
	}
	else if(response1.result == 'error')
	{
		stat.innerHTML = response1.errmsg;
	}
}

function on_failure(response)
{
	var stat = document.getElementById("stat");
	stat.innerHTML = response;
}
-->
</script>
<style type="text/css">
table td {
	 text-align:left;
}
table {
	margin-top:20px;
}
</style>
<div id="stat" style="display:none;"></div>
<form action="index.php" method="post" onsubmit="javascript:return check_assignrole_info(this);">
<table width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#4c4c4c">
<tr>
<td>用户名</td>
<?php
foreach($roles as $v)
{
	echo "<td>{$v['r_alias']}</td>";
}
?>
</tr>
<?php 
foreach($users as $v)
{
	echo "<tr>";
	echo "<td>{$v['u_name']}</td>";
	
	if($v['u_name'] == 'admin')
	{
		$enable = "disabled='disabled'";
	}
	else
	{
		$enable = '';
	}
	
	$role_list = explode(',',$v['u_role']);
	foreach($roles as $v1)
	{
		if(in_array($v1['r_role'],$role_list))
		{
			echo "<td><input $enable checked='checked' type='checkbox' name='{$v['u_name']}_{$v1['r_role']}' value='{$v1['r_role']}'/></td>";
		}
		else
		{
			echo "<td><input $enable type='checkbox' name='{$v['u_name']}_{$v1['r_role']}' value='{$v1['r_role']}'/></td>";
		}
	}
	
	echo "</tr>";
}
?>
</table>
<input type="submit" value="修改"/>
<input type="reset" value="重置"/>
<input type="hidden" name="_m" value="<?php echo $next_controller;?>"/>
<input type="hidden" name="_a" value="<?php echo $next_action;?>"/>
</form>
<p style="font-size:12px;font-weight:bold;">*建议:最好不要一人多个角色，可以分配角色的具体操作来实现</p>